<?php
$T->loadTpl("./html/".$template."/".$qname.".html");
$T->SetTpl('cssjs','html/cssjs.inc'); 
$T->SetTpl('jsmodel','html/jsmodel.inc');     
  
$p=isset($_GET["p"])?$_GET["p"]:"1";
$period=isset($_GET["period"])?$_GET["period"]:"";
$mechanism=isset($_GET["mechanism"])?$_GET["mechanism"]:"";
$dict=isset($_GET["dict"])?$_GET["dict"]:"";//所有子级元素包含自身的地区id
$ischeck=isset($_GET["ischeck"])?$_GET["ischeck"]:"";
$sch_name=isset($_GET["sch_name"])?htmlspecialchars($_GET["sch_name"],ENT_QUOTES):"";
$wh="";
$wh.=($period!='')?" and  A.period='{$period}' ":"";
$wh.=($mechanism!='')?" and  A.mechanism='{$mechanism}' ":"";
$wh.=($dict!='')?" and  A.areaid in ({$dict}) ":"";
$wh.=($ischeck!='')?" and  A.ischeck='{$ischeck}' ":"";
$wh.=($sch_name!='')?" and  A.sch_name like '%{$sch_name}%' ":"";
if($p<1)$p=1;

$no_sql="";
$pg_sql="";
//role
if(ckAdm()){
    $no_sql="select A.id,A.sch_name,A.period,A.flag,A.ischeck,C.name as mechanism_name,D.name as mtype_name,E.areaname as district from sys_school A left join sys_dict C on A.mechanism=C.id left join sys_dict D on A.mtype=D.id left join sys_area E on A.areaid=E.id where 1=1 {$wh} order by id desc limit ".(($p-1)*15).",15";
    $pg_sql="select count(1) from sys_school A where 1=1 {$wh}";
}else{
    $sch_model=$T->db->query("select a.*,b.name as typename from sys_school a left join sys_dict b on a.mechanism=b.id where a.id=1")->fetch(PDO::FETCH_ASSOC);
    if($sch_model){
        if($sch_model["typename"]=="教育局"){
            $wh.=" and (A.id=".$_SESSION["school"]."  or A.superior= ".$_SESSION["school"].") "; 
        }else{
            $wh.=" and A.id=".$_SESSION["school"]." ";
        }
        $no_sql="select A.id,A.sch_name,A.period,A.flag,A.ischeck,C.name as mechanism_name,D.name as mtype_name,E.areaname as district from sys_school A left join sys_dict C on A.mechanism=C.id left join sys_dict D on A.mtype=D.id left join sys_area E on A.areaid=E.id where 1=1 {$wh} order by id desc limit ".(($p-1)*15).",15";
        $pg_sql="select count(1) from sys_school A where 1=1 {$wh}";
    }
}

$rc=$T->db->query($pg_sql)->fetchColumn(0);
$page=getPageHtml_bt($rc,15,$p,"&t=system_school&period={$period}&mechanism={$mechanism}&dict={$dict}&ischeck={$ischeck}&sch_name={$sch_name}");
$page=mb_convert_encoding($page, 'utf-8', 'utf-8');
$T->Set("page",$page);

$T->SetBlock("school_list",$no_sql);
$T->Set("sch_name",$sch_name);
$T->Set("period",$period);
$T->Set("mechanism",$mechanism);
if($dict!=''){
	$dict=explode(",", $dict);
	$dict=$dict[0];//获取自身的地区id值
}
$T->Set("dict",$dict);
$T->Set("ischeck",$ischeck);
		

$T->Set("template",$template);         
$T->clearNaN();       
$T->clearNoN();
$T->display(); 